//
//  AlertTool.m
//  testHtml
//
//  Created by A.Jester on 28/03/2017.
//  Copyright © 2017 Eakay. All rights reserved.
//

#import "AlertTool.h"

typedef void (^confirm)();
typedef void (^cancle)();

@implementation AlertTool

+ (id)sharedInstance
{
    static AlertTool *_sharedClient = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _sharedClient = [[self alloc] init];
    });
    return _sharedClient;
}

- (void)showYesOrNoAlertView:(UIViewController *)viewController title:(NSString *)title message:(NSString *)message cancelBtnTitle:(NSString *)cancelBtnTitle confirmBtnTitle:(NSString *)confirmBtnTitle confirm:(void (^)())confirm cancle:(void (^)())cancle {

    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancelBtnTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        cancle();
    }];
    UIAlertAction *otherAction = [UIAlertAction actionWithTitle:confirmBtnTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        confirm();
    }];
    [alertController addAction:cancelAction];
    [alertController addAction:otherAction];
    [viewController presentViewController:alertController animated:YES completion:nil];
    
    
}
- (void)showAlertView:(UIViewController *)viewController title:(NSString *)title message:(NSString *)message confirmBtnTitle:(NSString *)confirmBtnTitle confirm:(void (^)())confirm{
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];

    UIAlertAction *otherAction = [UIAlertAction actionWithTitle:confirmBtnTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        confirm();
    }];
    [alertController addAction:otherAction];
    [viewController presentViewController:alertController animated:YES completion:nil];
}

- (void)showAlertViewInAppdelegate:(NSString *)title message:(NSString *)message cancelBtnTitle:(NSString *)cancelBtnTitle confirmBtnTitle:(NSString *)confirmBtnTitle confirm:(void (^)())confirm cancle:(void (^)())cancle
{
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancelBtnTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        cancle();
    }];
    UIAlertAction *otherAction = [UIAlertAction actionWithTitle:confirmBtnTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        confirm();
    }];
    [alertController addAction:cancelAction];
    [alertController addAction:otherAction];
    
    UIWindow *aW = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    aW.rootViewController = [[UIViewController alloc]init];
    aW.windowLevel = UIWindowLevelAlert + 1;
    [aW makeKeyAndVisible];
    [aW.rootViewController presentViewController:alertController animated:YES completion:nil];
}
@end



